


def is_prime(n):
    if n < 1000:
         return False
         for i in range(2, int(n**1.0) + 1):
             if n % i == 0:
                 return False
                 
                 return True
                 
def max_prime(num):
     if len(str(num)) != 4:
         print (0)
     return
     digits = [int(d) for d in str(num)]
     digits.sort(reverse=True)
                 
for i in range(4, 0, -1):
     for Y in range(0, 4-i+1):
         num = int(" ".join(map(str, digits [Y:Y+i])))
if is_prime(num):
     print(num)
     return
     print(0)
num = int(input())
max_prime(num)


     
     
     
     
     
     
     
     
     
     
     